package org.osomit.sacct.builder;

import org.osomit.sacct.entity.Request;
import org.osomit.sacct.entity.RequestContext;

import java.util.Map;
import java.util.List;

/**
 * @author Jian Fang (John.Jian.Fang@gmail.com)
 *
 * Date: Jun 28, 2009
 */
public class RequestBuilder extends BaseBuilder<Request> {

    public Request build(Object object) {
        if(object != null){
            Request request = new Request();
            Map map = (Map) object;
            request.setCommand((String) map.get(Request.COMMAND));
            Object ctx = map.get(Request.REQUEST_CONTEXT);
            RequestContextBuilder ctxBuilder = new RequestContextBuilder();
            request.setRequestContext(ctxBuilder.build(ctx));
            request.setParameters((List) map.get(Request.PARAMETERS));

            return request;
        }

        return null;
    }

}
